﻿using DapperExtensions;
using DapperExtensions.Sql;
using DotNet.Http.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;

namespace FXPushService
{
    public partial class Service1 : ServiceBase
    {
        Timer _timer = null;
        DataFetcher _fetcher = null;
        public Service1()
        {
            InitializeComponent();
        }


        //开始定时推送
        protected override void OnStart(string[] args)
        {
            var interval= ConfigurationManager.AppSettings["fetchInterval"];
            _timer = new Timer(1000 * 60 * int.Parse(interval));//10分钟1次
            _timer.Elapsed += _timer_Elapsed;
            _timer.AutoReset = false;


            _fetcher = new DataFetcher();
            _timer.Start();

        }
 
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _fetcher.GetRiver();
            _fetcher.GetResinfo();
            _fetcher.GetDayRain();
            _timer.Start();
        }

        protected override void OnStop()
        {
            _timer.Stop();
        }
    }
}
